<?php
/**
 * Created by PhpStorm.
 * User: xiong
 * Date: 2018/2/5
 * Time: 16:37
 */

namespace App\Http\Controllers\Auth;


use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;

class LoginController extends Controller
{
    public function show()
    {
        return view('auth.login', ['hasback' => true]);
    }

    public function login(Request $request)
    {
        $rules = [
            'username' => 'required',
            'password' => 'required'
        ];
        $data = $request->all(['username', 'password']);
//        dd($data);

        $user = User::wherePhone($request->phone)->first();
        if ($user) {
            if (\Hash::check($request->password, $user->password)) {
                \Auth::login($user);
                return response()->json(['msg' => '登录成功', 'code' => 200], 200);
            } else {
                return response()->json(['msg' => '密码错误', 'code' => 400], 200);
            }
        } else {
            return response()->json(['msg' => '账号不存在', 'code' => 400], 200);
        }
    }
}